package com.acme.bankapp.domain.account;

import java.io.Serializable;


@SuppressWarnings("serial")
public abstract class AbstractAccount implements Account, Serializable {
	protected static final String MSG_AMOUNT_NONPOSITIVE = "Amount must be positive.";
	
	
	protected static int currentId = 1;
	
	protected double balance;
	protected int id;
	
	public AbstractAccount(final double balance) {
		this.balance = balance;
		this.id = currentId++;
	}

	public void deposit(final double amount) {
		if (amount > 0) {
			this.balance += amount;
		} else {
			throw new IllegalArgumentException(MSG_AMOUNT_NONPOSITIVE);
		}
	}

	public double getBalance() {
		return this.balance;
	}
	
	public double getDecimalValue() {
		return Math.floor(balance);
	}

	public int getId() {
		return id;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AbstractAccount other = (AbstractAccount) obj;
		if (id != other.id)
			return false;
		return true;
	}
	
	
}
